//
//  ZSMainController.swift
//  新浪微博-Swift
//
//  Created by 周李波 on 16/7/19.
//  Copyright © 2016年 q. All rights reserved.
//

import UIKit

class ZSMainController: UITabBarController {
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义tabbar
        let tabBar = ZSTabBar()
        tabBar.zsDelegate = self
        setValue(tabBar, forKey: "TabBar")
        
       //添加子控件
        addChildViewController(ZSHomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(ZSMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZSDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZSProfileController(), title: "我", imageName: "tabbar_profile")
        
    }
    //MARK:- 创建子控制器
    func addChildViewController(childController: UIViewController, title:String, imageName:String) {
        childController.title = title
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : ThemeColor], forState: UIControlState.Selected)
       
        addChildViewController(UINavigationController(rootViewController: childController))
    }


}
//MARK:- 实现代理方法
extension ZSMainController:ZSTabBarDelegate{
    func composeButtonClick() {
        print("中间按钮点击了")
    }
}
